﻿@{
    Layout = "~/Views/Shared/_FormWhite.cshtml";
}
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment
@section header{
    <link href="@Url.Content("~/lib/summernote/0.8.15/summernote.min.css")" rel="stylesheet" type="text/css">
    <script src='@Url.Content("~/lib/summernote/0.8.15/summernote.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/lib/summernote/0.8.15/lang/summernote-zh-CN.min.js")' type="text/javascript"></script>

    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/imageupload/1.0/css/imgup.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/imageupload/1.0/js/imgup.min.js"))

    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/bootstrap.tagsinput/0.8.0/bootstrap-tagsinput.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/bootstrap.tagsinput/0.8.0/bootstrap-tagsinput.min.js"))
}

<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <div class="form-group">
            <label class="col-sm-2 control-label ">标题 <font class="red"> *</font> </label>
            <div class="col-sm-10">
                <input id="motoTitle" col="MotoTitle" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">副标题<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoSubtitle" col="MotoSubtitle" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">产品类型<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoT2" col="MotoT2" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">指导价<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoPrice" col="MotoPrice" type="text" class="form-control" />
            </div>
            @*<label class="col-sm-2 control-label ">市场均价<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoPrice1" col="MotoPrice1" type="text" class="form-control" />
            </div>*@
            <label class="col-sm-2 control-label ">排序<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoSort" col="MotoSort" type="text" class="form-control" />
            </div>

        </div>
        <div class="form-group">
           
            <label class="col-sm-2 control-label ">发布时间<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoDate" col="MotoDate" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">上市时间<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoTime" col="MotoTime" type="text" class="form-control" />
            </div>
        </div>
        <!------动力参数--------->
        <div class="form-group">
            <label class="col-sm-2 control-label ">型式<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoXingshi" col="MotoXingshi" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">排量<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoPailiang" col="MotoPailiang" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">压缩比<font class="red"> *</font></label>
            <div class="col-sm-2">
                <input id="motoYsb" col="MotoYsb" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">最大功率<font class="red"> *</font></label>
            <div class="col-sm-2">
                <input id="motoGonglv" col="MotoGonglv" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">颜色<font class="red"> *</font></label>
            <div class="col-sm-2">
                <input id="motoColor" col="MotoColor" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">最大扭矩<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoNiuju" col="MotoNiuju" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">供油方式<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoGongyou" col="MotoGongyou" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">排放标准<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoT1" col="MotoT1" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">离合器<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoLhq" col="MotoLhq" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">变速型式<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoBiansu" col="MotoBiansu" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">终端传动<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoChuandong" col="MotoChuandong" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">启动方式<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoQdfs" col="MotoQdfs" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">最高时速<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoJiasu" col="MotoJiasu" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">尺寸<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoCkg" col="MotoCkg" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">离地间隙<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoLdjx" col="MotoLdjx" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">整备质量<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoZhiliang" col="MotoZhiliang" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">油箱容量<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoYxrl" col="MotoYxrl" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">轴距<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoAuthor" col="MotoAuthor" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">减震方式<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoJianzhen" col="MotoJianzhen" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">前制动<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoQzd" col="MotoQzd" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">后制动<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoHzd" col="MotoHzd" type="text" class="form-control" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">前轮规格<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoQianlun" col="MotoQianlun" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">后轮规格<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoHoulun" col="MotoHoulun" type="text" class="form-control" />
            </div>
        </div>

        @*@await Html.PartialAsync("/Areas/SystemManage/Shared/AreaFormPartial.cshtml", new ViewDataDictionary(this.ViewData) { { "Label", "2" }, { "Content", "10" } })*@
        
        <div class="form-group">
            <label class="col-sm-2 control-label ">外部链接<font class="red"> *</font></label>
            <div class="col-sm-4">
                <input id="motoUrl" col="MotoUrl" type="text" class="form-control" />
            </div>
            <label class="col-sm-2 control-label ">
                <span>封面</span><br />
                <span>(宽高比 1.5：1)</span>
            </label>
            <div class="col-sm-4">
                <div id="coverImage" class="img-box"></div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">
                <span>缩略图</span><br />
                <span>(宽高比 1.5：1)</span>
            </label>
            <div class="col-sm-10">
                <div id="thumbImage" class="img-box">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">备注<font class="red"> *</font></label>
            <div class="col-sm-10">
                <textarea id="motoRemarks" col="MotoRemarks" class="form-control"></textarea>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">文章内容 </label>
            <div class="col-sm-10">
                <div id="motoContent" class="summernote"></div>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    $(function () {
        laydate.render({ elem: '#motoDate', type: 'datetime', format: 'yyyy-MM-dd HH:mm' });

        $('#motoTag').tagsinput({ trimValue: true });

        $("#motoType").ysComboBox({
            data: top.getDataDict("MotoType"),
            key: "DictKey",
            value: "DictValue",
            class: "form-control"
        });

        $('#motoContent').summernote({
            height: '220px',
            lang: 'zh-CN',
            dialogsInBody: true,
            callbacks: {
                onImageUpload: function (files, editor, welEditable) {
                    uploadnewsImage(files[0], editor, welEditable);
                }
            }
        });

        $("#thumbImage").imageUpload({ uploadImage: 'uploadThumbImage', limit: 10, context: ctx });
        $("#coverImage").imageUpload({ uploadImage: 'uploadThumbImage', limit: 1, context: ctx });
        getForm();

        $("#form").validate({
            rules: {
                motoTitle: { required: true },
                motoType_select: { required: true },
                motoDate: { required: true },
                motoAuthor: { required: true },
                
            }
        });
    });

    function getForm() {
        if (id > 0) {
            ys.ajax({
                url: '@Url.Content("~/OrganizationManage/moto/GetFormJson")' + '?id=' + id,
                type: "get",
                success: function (obj) {
                    if (obj.Tag == 1) {
                        obj.Result.motoDate = ys.formatDate(obj.Result.MotoDate, "yyyy-MM-dd HH:mm");
                        $("#form").setWebControls(obj.Result);
                        $("#motoContent").summernote('code', obj.Result.MotoContent);
                        $("#thumbImage").imageUpload("setImageUrl", obj.Result.ThumbImage);
                        $("#coverImage").imageUpload("setImageUrl", obj.Result.CoverImage);
                       
                    }
                }
            });
        }
        else {
            ys.ajax({
                url: '@Url.Content("~/OrganizationManage/moto/GetMaxSortJson")',
                type: "get",
                success: function (obj) {
                    if (obj.Tag == 1) {
                        var defaultData = {};
                       
                        defaultData.MotoDate = '@DateTime.Now.ToString("yyyy-MM-dd HH:mm")';
                      
                        $("#form").setWebControls(defaultData);
                    }
                }
            });
        }
    }

    function saveForm(index) {
        if ($("#form").validate().form()) {
            var postData = $("#form").getWebControls({ Id: id });
            postData.MotoContent = $("#motoContent").summernote('code');
            postData.ThumbImage = $("#thumbImage").imageUpload("getImageUrl");
            postData.CoverImage = $("#coverImage").imageUpload("getImageUrl");
            ys.ajax({
                url: '@Url.Content("~/OrganizationManage/moto/SaveFormJson")',
                type: "post",
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        }
    }

    function uploadnewsImage(file, editor, welEditable) {
        var formdata = new FormData();
        formdata.append("fileList", file);
        ys.ajaxUploadFile({
            url: '@GlobalContext.SystemConfig.ApiSite' + '/File/UploadFile?fileModule=@UploadFileType.News.ParseToInt()',
            data: formdata,
            success: function (obj) {
                if (obj.Tag == 1) {
                    $("#motoContent").summernote('insertImage', '@GlobalContext.SystemConfig.ApiSite' + obj.Result, '/');
                }
                else {
                    ys.msgError(obj.Message);
                }
            }
        })
    }

    function uploadThumbImage(file, callback) {
        var formdata = new FormData();
        formdata.append("fileList", file);
        ys.ajaxUploadFile({
            url: '@GlobalContext.SystemConfig.ApiSite' + '/File/UploadFile?fileModule=@UploadFileType.News.ParseToInt()',
            data: formdata,
            success: function (obj) {
                if (obj.Tag == 1) {
                    if (callback) {
                        callback('@GlobalContext.SystemConfig.ApiSite' + obj.Result);
                    }
                }
                else {
                    ys.msgError(obj.Message);
                }
            }
        })
    }
</script>

